package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws Exception {
        //调用Person类中的sayHello方法

        //1.实例化Person并调用sayHello方法
        /*
           优点：直接明了
           缺点：代码写死，
         */
        Person p = new Person();
        p.sayHello();

        //2.反射调用
        Class cls = Class.forName("demo1.Person");
        Person p1 = (Person)cls.newInstance();
        p1.sayHello();

        //3.使用Spring容器
        AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext("demo1");
        Person p2 = ctx.getBean(Person.class);
        p2.sayHello();
    }
}
